<?php

namespace App\Http\Controllers\Api;

use Cblink\Region\Region;
use Illuminate\Http\Request;

class AreasController extends Controller
{
    protected $region;

    public function __construct()
    {
        $this->region = new Region();
    }

    public function index(Request $request)
    {
        if ($pid = $request->input('pid')) {
            $children = $this->region->nest($pid)[0]['children'];
            return $this->success($children);
        }
        return $this->success($this->region->allProvinces());
    }
}
